package com.agy.filemanager.service.impl;

import com.agy.filemanager.common.StringUtils;
import com.agy.filemanager.entity.ProExpandInfo;
import com.agy.filemanager.entity.ProExpandInfoExample;
import com.agy.filemanager.mapper.ProExpandInfoMapper;
import com.agy.filemanager.service.ProExpandInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class ProExpandInfoServiceImpl implements ProExpandInfoService {
    @Autowired
    private ProExpandInfoMapper proExpandInfoMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public String insertProTypeExpandCloumnByTypeId(ProExpandInfo info) {
        String id = StringUtils.getUUID();
        info.setId(id);
        proExpandInfoMapper.insertSelective(info);
        return id;
    }

    @Override
    public void deleteProTypeExpandById(String id) {
        proExpandInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateProTypeExpandById(ProExpandInfo info) {
        proExpandInfoMapper.updateByPrimaryKeySelective(info);
    }

    @Override
    public List<ProExpandInfo> getProExpandListByProjectInfoId(String id) {
        List<ProExpandInfo> proExpandInfos = proExpandInfoMapper.getProExpandListByProjectInfoId(id);
        return  proExpandInfos;
    }

    @Override
    public List<ProExpandInfo> getProExpandListByProTypeId(String proTypeId) {
        ProExpandInfoExample example = new ProExpandInfoExample();
        example.setOrderByClause("SORT ASC");
        ProExpandInfoExample.Criteria criteria = example.createCriteria();
        criteria.andProjectTypeidEqualTo(proTypeId);
        List<ProExpandInfo> proExpandInfos = proExpandInfoMapper.selectByExample(example);
        return proExpandInfos;
    }
}
